import Matrix from "../../../Matrix/Matrix";
import { MapGenerator } from "../..";
import { MAP } from "../../Types";
import { TILE } from "../../enum";
import { Coord } from "../../utils/Coord";
import { GetRegionTiles } from "./GetRegionTiles";

export function GetRegions(
    tileType: TILE,
    map: MAP,
    MapGenerator: MapGenerator
) {
    const regions: Coord[][] = [];
    /** 被查询过的地点，如果这个位置上为1 ，那么表示被查询过 */
    const Founded = new Matrix<0 | 1>({
        height: MapGenerator.height,
        width: MapGenerator.width,
        voidValue: 0,
    });

    map.$forEach((value, x, y) => {
        if (Founded.get(x, y) === 0 && value === tileType) {
            let region = GetRegionTiles(x, y, map, tileType, Founded);
            regions.push(region);
        }
    });
    return regions;
}
